package FunctionDemo.demo3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.function.IntFunction;

public class test {
    public static void main(String[] args){
        // 创建集合
        ArrayList<String> list = new ArrayList<>();
        // 添加数据
        Collections.addAll(list, "zhangsan,19", "lisi,21", "wangwu,29");
        // 对数据进行操作
        // Student[] sarr = list.stream().map(new Function<String, Student>() {
        //     @Override
        //     public Student apply(String s){
        //         return new Student(s.split(",")[0], Integer.parseInt(s.split(",")[1]));
        //     }
        // }).toArray(new IntFunction<Student[]>() {
        //     @Override
        //     public Student[] apply(int len){
        //         return new Student[len];
        //     }
        // });
        Student[] sarr = list.stream().map(Student::new).toArray(Student[]::new);
        for (int i = 0; i < sarr.length; i++) {
            System.out.println(sarr[i].getName() + ", "+ sarr[i].getAge());
        }
    }
}
